/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.farmcode.web.generation.objectinfo;

import com.farmcode.api.runtime.FARMCodeContext;
import com.farmcode.api.runtime.metadata.ViewSpc;
import com.farmcode.web.project.DatasourceBackingBean;
import javax.faces.bean.RequestScoped;
import javax.inject.Named;

/**
 *
 * @author Oscar Ivan Prado
 */
@Named("viewsBackingBean")
@RequestScoped
public class ViewsBackingBean extends BaseObjectInfo {

    public static final String OBJECTS_INFO = ViewsBackingBean.class.getName() + ".objectInfo";
    
    public static final String SELECTED_ALL = TablesBackingBean.class.getName() + ".selectedAll";
    
    /** Creates a new instance of ViewBackingBean */
    public ViewsBackingBean() {
    }

    @Override
    public Object getObjectType() {
        return new ViewSpc();
    }
    
    @Override
    public String getObjectInfoSessionName() {
        return OBJECTS_INFO;
    }

    @Override
    public String getSelectedAllSessionName() {
        return SELECTED_ALL;
    }

    @Override
    public boolean prepare() {
        getContext().put(FARMCodeContext.OBJECT_TYPE, "view");
            
        String plugin = getSession().getValue(FARMCodeContext.OBJECT_INFO_PLUGIN_MANAGER);
        if(plugin != null && plugin.equals(DatasourceBackingBean.JDBC_DATABASE_EXPLORER)){

            String host = getSession().getValue(FARMCodeContext.HOST);
            String driver = getSession().getValue(FARMCodeContext.DRIVER);
            String user = getSession().getValue(FARMCodeContext.USER);
            String password = getSession().getValue(FARMCodeContext.PASSWORD);
            String schema = getSession().getValue(FARMCodeContext.SCHEMA);

            getContext().put(FARMCodeContext.DRIVER, driver);
            getContext().put(FARMCodeContext.HOST, host);
            getContext().put(FARMCodeContext.USER, user);
            getContext().put(FARMCodeContext.PASSWORD, password);
            getContext().put(FARMCodeContext.SCHEMA, schema);
            return true;
        }
        return false;
        
    }

    
}
